//
//  InputSearchViewController.m
//  TodatPlay
//
//  Created by dllo on 16/9/19.
//  Copyright © 2016年 DM.C. All rights reserved.
//

#import "InputSearchViewController.h"

@interface InputSearchViewController ()<UISearchBarDelegate, UITableViewDataSource, UITableViewDelegate, UISearchControllerDelegate, UISearchResultsUpdating, UISearchDisplayDelegate>
// 存放所有数据的数组
@property (nonatomic, retain) NSMutableArray *allDataArray;
// 存放搜索出结果的数组
@property (nonatomic, retain) NSMutableArray *searchResultDataArray;
// 搜索使用的表示图控制器
@property (nonatomic, retain) UITableViewController *searchTVC;
// 搜索框输入的东西
@property (nonatomic, copy) NSString *inputText;
@end

@implementation InputSearchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.searchResultsUpdater = self;
    self.delegate = self;
    self.searchBar.placeholder = @"搜索类型";
}
#pragma mark - UISearchResultsUpdating Method
#pragma mark 监听者搜索框中的值的变化
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController
{
    // 1. 获取输入的值
    self.inputText = searchController.searchBar.text;
    
}

//4. 请求数据并解析(我这里用的时AFN请求, 其他方法都可以,随意)
// afnq请求数据(搜索数据)

// 设置搜索tableView cell个数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (_searchResultDataArray.count == 0) {
        NSLog(@"33333");
        return 1;
    }
    return _searchResultDataArray.count;
}

// 设置搜索tableView的cell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIdentifier = @"indenfy";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }
    if (self.searchResultDataArray.count != 0) {
        
    }else{
        cell.textLabel.text = @"没有查找的内容";
        cell.imageView.image = nil;
    }
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    
    [self presentedViewController];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
